package com.chtmlCoder.rcc;

import com.intellij.openapi.actionSystem.AnAction;
import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.openapi.actionSystem.PlatformDataKeys;
import java.awt.Desktop;
import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;

public class rightMenuOpenUrl extends AnAction {

    @Override
    public void actionPerformed(AnActionEvent e) {
        // 获取鼠标右键传递的文本信息
        String selectedText = e.getData(PlatformDataKeys.EDITOR).getSelectionModel().getSelectedText();
        String theUrl = "http://www.chtml.cn/w?word=" + selectedText;
        // 打开URL链接
        try {
            Desktop.getDesktop().browse(new URI(theUrl));
        } catch (IOException | URISyntaxException ex) {
            ex.printStackTrace();
        }
    }
}
